package pl.edu.amu.wmi.kino.visualjavafx.model.animation.transformations;

import java.awt.Color;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import pl.edu.amu.wmi.kino.visualjavafx.model.animation.interpolators.Interpolation;
import pl.edu.amu.wmi.kino.visualjavafx.model.objects.VisualObject;

// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.EAC97A39-E2C4-FEB3-07A4-9D958BB3D63E]
// </editor-fold> 
public class ChangeBorderColor implements Transformation ,java.io.Serializable{

    // Code block for changeListeners support start
    protected PropertyChangeSupport propertySupport= new PropertyChangeSupport(this);
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.addPropertyChangeListener(listener);
    }
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.removePropertyChangeListener(listener);
    }
    // Code block for changeListeners support end

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.819DED63-AF26-9DB9-2808-4DC15AB93838]
    // </editor-fold> 
    public ChangeBorderColor () {
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.A16ED2A6-F034-44A5-AAC5-B774B206B13D]
    // </editor-fold> 
    @Override
    public Interpolation getInterpolation () {
        return this.myInterpolations[0];
    }
    @Override
    public Interpolation[] getInterpolations() {
        return this.myInterpolations;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.E39658C9-A41F-313E-7519-2C30694BEAF4]
    // </editor-fold> 
    @Override
    public void setInterpolation (Interpolation i) {
        Interpolation oldVal = this.myInterpolations[0];
        this.myInterpolations[0]=i;
        this.myInterpolations[1]=i;
        this.myInterpolations[2]=i;
        propertySupport.firePropertyChange( "Inerpolation" , oldVal, i);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.C346AA0B-5493-7440-A360-DF386EF9C4E1]
    // </editor-fold> 
    @Override
    public VisualObject transform (double howMuch, VisualObject transformable,VisualObject orginalTransformedObject) {

        if ((transformable instanceof WithBorder)==false){
            return transformable;
        }
        
        WithBorder res =(WithBorder) transformable;

        double r = res.getBorderColor().getRed();
        double g = res.getBorderColor().getGreen();
        double b = res.getBorderColor().getBlue();

        r=this.myInterpolations[0].getValue(howMuch, r, this.destinedColor.getRed());
        g=this.myInterpolations[1].getValue(howMuch, g, this.destinedColor.getGreen());
        b=this.myInterpolations[2].getValue(howMuch, b, this.destinedColor.getBlue());


        res.setBorderColor(new Color((int)r,(int)g,(int)b));
        return (VisualObject)res;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.BDE7221C-6A29-49E7-3105-8B2D08E45569]
    // </editor-fold> 
    public Color getDestinedColor () {
        return this.destinedColor;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.6190CD6C-DECF-AAE3-E188-1431C4FE177C]
    // </editor-fold> 
    public void setDestinedColor (Color val) {
        Color oldVal = this.destinedColor;
        this.destinedColor=val;
        propertySupport.firePropertyChange( "destinedColor" , oldVal, val);
    }

    private Interpolation[] myInterpolations=new Interpolation[3];
    private Color destinedColor=Color.BLACK;



}

